package com.enation.app.javashop.api.client;

import com.enation.app.javashop.model.member.dos.ConnectDO;
import com.enation.app.javashop.model.payment.enums.WechatTypeEnmu;
import com.enation.app.javashop.service.member.ConnectManager;
import com.enation.app.javashop.service.passport.signaturer.WechatSignaturer;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

/**
 * 会员收藏商品相关api
 *
 * @author zh
 * @version v7.0
 * @date 18/7/30 下午8:10
 * @since v7.0
 */
@Api(description = "会员收藏商品api")
@RestController
@RequestMapping("/client/members")
@Validated
@ApiIgnore
public class ConnectClientController {

    @Autowired
    private ConnectManager connectManager;

    @Autowired
    private WechatSignaturer wechatSignaturer;

    @RequestMapping(value = "/{member_id}/connect", method = RequestMethod.GET)
    public ConnectDO getConnect(@PathVariable("member_id") Long memberId, @RequestParam("union_type") String unionType) {
        return connectManager.getConnect(memberId, unionType);
    }

    @RequestMapping(value = "/{member_id}/open-id", method = RequestMethod.GET)
    String getMemberOpenid(@PathVariable("member_id")Long memberId){

       return wechatSignaturer.getMemberOpenid(memberId);
    }

    @RequestMapping(value = "/cgi-access-token", method = RequestMethod.GET)
    String getCgiAccessToken(@RequestParam("wechat_type_enmu") WechatTypeEnmu wechatTypeEnmu){

        return wechatSignaturer.getCgiAccessToken(wechatTypeEnmu);
    }

    @RequestMapping(value = "/connect-config", method = RequestMethod.GET)
    Map getConnectConfig(@RequestParam("wechat_type_enmu")WechatTypeEnmu wechatTypeEnmu){

        return wechatSignaturer.getConnectConfig(wechatTypeEnmu.name());
    }

}
